package cn.new18.testactivitytask.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.new18.testactivitytask.R;
import cn.new18.testactivitytask.adapter.BFragFragAapter;

/**
 * Created by RaoWei on 2016/11/11 18:41.
 */

public class B extends FragmentActivity {
    @BindView(R.id.b_tablayout)
    TabLayout mTablayout;
    @BindView(R.id.b_viewpager)
    ViewPager mViewpager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.b);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        mViewpager.setOffscreenPageLimit(1);  //左右两边预加载的页面数，系统默认为1
        mViewpager.setAdapter(new BFragFragAapter(getSupportFragmentManager()));
        mTablayout.addTab(mTablayout.newTab());
        mTablayout.addTab(mTablayout.newTab());
        mTablayout.addTab(mTablayout.newTab());
        mTablayout.addTab(mTablayout.newTab());
        mTablayout.setupWithViewPager(mViewpager);
    }
}
